#include<bits/stdc++.h>
using namespace std;

struct car{
	int d, v, a;
};

struct ite{
	int l, r;
	bool operator < (const ite &a) const{
		if (r != a.r) return r < a.r;
		return l < a.l;
	}
};

int T;
int N, M, L, V;
int cnt = 0; // ans1
car a[100005];
int p[100005];
int sum[1000006];
int st[100005], en[100005]; // chao su qu jian
vector<ite> it;

void operate(int pos, int d, int v, int a, int V){
	if (a == 0){
		if (v > V){
			st[pos] = d, en[pos] = L;
		}else{
			st[pos] = en[pos] = -1;
		}
	}else if (a > 0){
		if (v > V){
			st[pos] = d, en[pos] = L;
		}else{
			int dis = 0;
			if ((V * V - v * v) % (2 * a) == 0){
				dis = (V * V - v * v) / (2 * a) + 1;
			}else{
				double tmp = 1.0 * (V * V - v * v) / (2 * a);
				dis = ceil(tmp);
			}
			if (d + dis <= L){
				st[pos] = d + dis, en[pos] = L;
			}else{
				st[pos] = en[pos] = -1;
			}
		}
	}else{ // a < 0
		if (v <= V){
			st[pos] = en[pos] = -1;
		}else{
			int dis = 0;
			if ((V * V - v * v) % (2 * a) == 0){
				dis = (V * V - v * v) / (2 * a) - 1;
			}else{
				double tmp = 1.0 * (V * V - v * v) / (2 * a);
				dis = floor(tmp);
			}
			if (d + dis >= L){
				st[pos] = d, en[pos] = L;
			}else{
				st[pos] = d, en[pos] = d + dis;
			}
		}
	}
}

int main(){
	freopen("detect.in", "r", stdin);
	freopen("detect.out", "w", stdout);
	
	scanf("%d", &T);
	while (T --){
		scanf("%d %d %d %d", &N, &M, &L, &V);
		for (int i = 0; i <= L + 2; i ++){
			sum[i] = 0;
		}
		it.clear();
		// init
		// -------------------------------------------------------------
		for (int i = 0; i < N; i ++){
			scanf("%d %d %d", &a[i].d, &a[i].v, &a[i].a);
		}
		for (int i = 0; i < M; i ++){
			scanf("%d", &p[i]);
			sum[p[i] + 1] ++;
		}
		for (int i = 1; i <= L + 1; i ++){
			sum[i] += sum[i - 1];
		}
		for (int i = 0; i < N; i ++){
			operate(i, a[i].d, a[i].v, a[i].a, V);
		}
		// -------------------------------------------------------------
		// ans1
		cnt = 0;
		for (int i = 0; i < N; i ++){
			// cout << i << " " << st[i] << " " << en[i] << ";;\n";
			if (en[i] < 0) continue;
			if (sum[en[i] + 1] - sum[st[i]] <= 0) continue;
			cnt ++;
			it.push_back({st[i], en[i]});
		}
		printf("%d ", cnt);
		// -------------------------------------------------------------
		// ans2
		int res = M;
		sort(it.begin(), it.end());
		int las = -1; // laspos
		for (auto && i : it){
			int l = i.l, r = i.r;
			// cout << l << " " << r << "      " << las << "\n";
			if (las >= l) continue;
			int pos = upper_bound(p, p + M, r) - p - 1;
			// cout << pos << " " << p[pos] << ";;\n";
			las = p[pos], res --;
		}
		printf("%d\n", res);
	}

	return 0;
}
